home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 24 / AACD 24.iso / AACD / Programming / gcc-2.95.3-3 / info / gcc.info-10 < prev    next >
Encoding:
GNU Info File  |  2001-07-15  |  41.7 KB  |  1,066 lines

  1. This is Info file gcc.info, produced by Makeinfo version 1.68 from the
  2. input file ./gcc.texi.
  3.  
  4. INFO-DIR-SECTION Programming
  5. START-INFO-DIR-ENTRY
  6. * gcc: (gcc).                  The GNU Compiler Collection.
  7. END-INFO-DIR-ENTRY
  8.    This file documents the use and the internals of the GNU compiler.
  9.  
  10.    Published by the Free Software Foundation 59 Temple Place - Suite 330
  11. Boston, MA 02111-1307 USA
  12.  
  13.    Copyright (C) 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
  14. 1999, 2000 Free Software Foundation, Inc.
  15.  
  16.    Permission is granted to make and distribute verbatim copies of this
  17. manual provided the copyright notice and this permission notice are
  18. preserved on all copies.
  19.  
  20.    Permission is granted to copy and distribute modified versions of
  21. this manual under the conditions for verbatim copying, provided also
  22. that the sections entitled "GNU General Public License" and "Funding
  23. for Free Software" are included exactly as in the original, and
  24. provided that the entire resulting derived work is distributed under
  25. the terms of a permission notice identical to this one.
  26.  
  27.    Permission is granted to copy and distribute translations of this
  28. manual into another language, under the above conditions for modified
  29. versions, except that the sections entitled "GNU General Public
  30. License" and "Funding for Free Software", and this permission notice,
  31. may be included in translations approved by the Free Software Foundation
  32. instead of in the original English.
  33.  
  34. 
  35. File: gcc.info,  Node: Variable Length,  Next: Macro Varargs,  Prev: Zero Length,  Up: C Extensions
  36.  
  37. Arrays of Variable Length
  38. =========================
  39.  
  40.    Variable-length automatic arrays are allowed in GNU C.  These arrays
  41. are declared like any other automatic arrays, but with a length that is
  42. not a constant expression.  The storage is allocated at the point of
  43. declaration and deallocated when the brace-level is exited.  For
  44. example:
  45.  
  46.      FILE *
  47.      concat_fopen (char *s1, char *s2, char *mode)
  48.      {
  49.        char str[strlen (s1) + strlen (s2) + 1];
  50.        strcpy (str, s1);
  51.        strcat (str, s2);
  52.        return fopen (str, mode);
  53.      }
  54.  
  55.    Jumping or breaking out of the scope of the array name deallocates
  56. the storage.  Jumping into the scope is not allowed; you get an error
  57. message for it.
  58.  
  59.    You can use the function `alloca' to get an effect much like
  60. variable-length arrays.  The function `alloca' is available in many
  61. other C implementations (but not in all).  On the other hand,
  62. variable-length arrays are more elegant.
  63.  
  64.    There are other differences between these two methods.  Space
  65. allocated with `alloca' exists until the containing *function* returns.
  66. The space for a variable-length array is deallocated as soon as the
  67. array name's scope ends.  (If you use both variable-length arrays and
  68. `alloca' in the same function, deallocation of a variable-length array
  69. will also deallocate anything more recently allocated with `alloca'.)
  70.  
  71.    You can also use variable-length arrays as arguments to functions:
  72.  
  73.      struct entry
  74.      tester (int len, char data[len][len])
  75.      {
  76.        ...
  77.      }
  78.  
  79.    The length of an array is computed once when the storage is allocated
  80. and is remembered for the scope of the array in case you access it with
  81. `sizeof'.
  82.  
  83.    If you want to pass the array first and the length afterward, you can
  84. use a forward declaration in the parameter list--another GNU extension.
  85.  
  86.      struct entry
  87.      tester (int len; char data[len][len], int len)
  88.      {
  89.        ...
  90.      }
  91.  
  92.    The `int len' before the semicolon is a "parameter forward
  93. declaration", and it serves the purpose of making the name `len' known
  94. when the declaration of `data' is parsed.
  95.  
  96.    You can write any number of such parameter forward declarations in
  97. the parameter list.  They can be separated by commas or semicolons, but
  98. the last one must end with a semicolon, which is followed by the "real"
  99. parameter declarations.  Each forward declaration must match a "real"
  100. declaration in parameter name and data type.
  101.  
  102. 
  103. File: gcc.info,  Node: Macro Varargs,  Next: Subscripting,  Prev: Variable Length,  Up: C Extensions
  104.  
  105. Macros with Variable Numbers of Arguments
  106. =========================================
  107.  
  108.    In GNU C, a macro can accept a variable number of arguments, much as
  109. a function can.  The syntax for defining the macro looks much like that
  110. used for a function.  Here is an example:
  111.  
  112.      #define eprintf(format, args...)  \
  113.       fprintf (stderr, format , ## args)
  114.  
  115.    Here `args' is a "rest argument": it takes in zero or more
  116. arguments, as many as the call contains.  All of them plus the commas
  117. between them form the value of `args', which is substituted into the
  118. macro body where `args' is used.  Thus, we have this expansion:
  119.  
  120.      eprintf ("%s:%d: ", input_file_name, line_number)
  121.      ==>
  122.      fprintf (stderr, "%s:%d: " , input_file_name, line_number)
  123.  
  124. Note that the comma after the string constant comes from the definition
  125. of `eprintf', whereas the last comma comes from the value of `args'.
  126.  
  127.    The reason for using `##' is to handle the case when `args' matches
  128. no arguments at all.  In this case, `args' has an empty value.  In this
  129. case, the second comma in the definition becomes an embarrassment: if
  130. it got through to the expansion of the macro, we would get something
  131. like this:
  132.  
  133.      fprintf (stderr, "success!\n" , )
  134.  
  135. which is invalid C syntax.  `##' gets rid of the comma, so we get the
  136. following instead:
  137.  
  138.      fprintf (stderr, "success!\n")
  139.  
  140.    This is a special feature of the GNU C preprocessor: `##' before a
  141. rest argument that is empty discards the preceding sequence of
  142. non-whitespace characters from the macro definition.  (If another macro
  143. argument precedes, none of it is discarded.)
  144.  
  145.    It might be better to discard the last preprocessor token instead of
  146. the last preceding sequence of non-whitespace characters; in fact, we
  147. may someday change this feature to do so.  We advise you to write the
  148. macro definition so that the preceding sequence of non-whitespace
  149. characters is just a single token, so that the meaning will not change
  150. if we change the definition of this feature.
  151.  
  152. 
  153. File: gcc.info,  Node: Subscripting,  Next: Pointer Arith,  Prev: Macro Varargs,  Up: C Extensions
  154.  
  155. Non-Lvalue Arrays May Have Subscripts
  156. =====================================
  157.  
  158.    Subscripting is allowed on arrays that are not lvalues, even though
  159. the unary `&' operator is not.  For example, this is valid in GNU C
  160. though not valid in other C dialects:
  161.  
  162.      struct foo {int a[4];};
  163.      
  164.      struct foo f();
  165.      
  166.      bar (int index)
  167.      {
  168.        return f().a[index];
  169.      }
  170.  
  171. 
  172. File: gcc.info,  Node: Pointer Arith,  Next: Initializers,  Prev: Subscripting,  Up: C Extensions
  173.  
  174. Arithmetic on `void'- and Function-Pointers
  175. ===========================================
  176.  
  177.    In GNU C, addition and subtraction operations are supported on
  178. pointers to `void' and on pointers to functions.  This is done by
  179. treating the size of a `void' or of a function as 1.
  180.  
  181.    A consequence of this is that `sizeof' is also allowed on `void' and
  182. on function types, and returns 1.
  183.  
  184.    The option `-Wpointer-arith' requests a warning if these extensions
  185. are used.
  186.  
  187. 
  188. File: gcc.info,  Node: Initializers,  Next: Constructors,  Prev: Pointer Arith,  Up: C Extensions
  189.  
  190. Non-Constant Initializers
  191. =========================
  192.  
  193.    As in standard C++, the elements of an aggregate initializer for an
  194. automatic variable are not required to be constant expressions in GNU C.
  195. Here is an example of an initializer with run-time varying elements:
  196.  
  197.      foo (float f, float g)
  198.      {
  199.        float beat_freqs[2] = { f-g, f+g };
  200.        ...
  201.      }
  202.  
  203. 
  204. File: gcc.info,  Node: Constructors,  Next: Labeled Elements,  Prev: Initializers,  Up: C Extensions
  205.  
  206. Constructor Expressions
  207. =======================
  208.  
  209.    GNU C supports constructor expressions.  A constructor looks like a
  210. cast containing an initializer.  Its value is an object of the type
  211. specified in the cast, containing the elements specified in the
  212. initializer.
  213.  
  214.    Usually, the specified type is a structure.  Assume that `struct
  215. foo' and `structure' are declared as shown:
  216.  
  217.      struct foo {int a; char b[2];} structure;
  218.  
  219. Here is an example of constructing a `struct foo' with a constructor:
  220.  
  221.      structure = ((struct foo) {x + y, 'a', 0});
  222.  
  223. This is equivalent to writing the following:
  224.  
  225.      {
  226.        struct foo temp = {x + y, 'a', 0};
  227.        structure = temp;
  228.      }
  229.  
  230.    You can also construct an array.  If all the elements of the
  231. constructor are (made up of) simple constant expressions, suitable for
  232. use in initializers, then the constructor is an lvalue and can be
  233. coerced to a pointer to its first element, as shown here:
  234.  
  235.      char **foo = (char *[]) { "x", "y", "z" };
  236.  
  237.    Array constructors whose elements are not simple constants are not
  238. very useful, because the constructor is not an lvalue.  There are only
  239. two valid ways to use it: to subscript it, or initialize an array
  240. variable with it.  The former is probably slower than a `switch'
  241. statement, while the latter does the same thing an ordinary C
  242. initializer would do.  Here is an example of subscripting an array
  243. constructor:
  244.  
  245.      output = ((int[]) { 2, x, 28 }) [input];
  246.  
  247.    Constructor expressions for scalar types and union types are is also
  248. allowed, but then the constructor expression is equivalent to a cast.
  249.  
  250. 
  251. File: gcc.info,  Node: Labeled Elements,  Next: Cast to Union,  Prev: Constructors,  Up: C Extensions
  252.  
  253. Labeled Elements in Initializers
  254. ================================
  255.  
  256.    Standard C requires the elements of an initializer to appear in a
  257. fixed order, the same as the order of the elements in the array or
  258. structure being initialized.
  259.  
  260.    In GNU C you can give the elements in any order, specifying the array
  261. indices or structure field names they apply to.  This extension is not
  262. implemented in GNU C++.
  263.  
  264.    To specify an array index, write `[INDEX]' or `[INDEX] =' before the
  265. element value.  For example,
  266.  
  267.      int a[6] = { [4] 29, [2] = 15 };
  268.  
  269. is equivalent to
  270.  
  271.      int a[6] = { 0, 0, 15, 0, 29, 0 };
  272.  
  273. The index values must be constant expressions, even if the array being
  274. initialized is automatic.
  275.  
  276.    To initialize a range of elements to the same value, write `[FIRST
  277. ... LAST] = VALUE'.  For example,
  278.  
  279.      int widths[] = { [0 ... 9] = 1, [10 ... 99] = 2, [100] = 3 };
  280.  
  281. Note that the length of the array is the highest value specified plus
  282. one.
  283.  
  284.    In a structure initializer, specify the name of a field to initialize
  285. with `FIELDNAME:' before the element value.  For example, given the
  286. following structure,
  287.  
  288.      struct point { int x, y; };
  289.  
  290. the following initialization
  291.  
  292.      struct point p = { y: yvalue, x: xvalue };
  293.  
  294. is equivalent to
  295.  
  296.      struct point p = { xvalue, yvalue };
  297.  
  298.    Another syntax which has the same meaning is `.FIELDNAME ='., as
  299. shown here:
  300.  
  301.      struct point p = { .y = yvalue, .x = xvalue };
  302.  
  303.    You can also use an element label (with either the colon syntax or
  304. the period-equal syntax) when initializing a union, to specify which
  305. element of the union should be used.  For example,
  306.  
  307.      union foo { int i; double d; };
  308.      
  309.      union foo f = { d: 4 };
  310.  
  311. will convert 4 to a `double' to store it in the union using the second
  312. element.  By contrast, casting 4 to type `union foo' would store it
  313. into the union as the integer `i', since it is an integer.  (*Note Cast
  314. to Union::.)
  315.  
  316.    You can combine this technique of naming elements with ordinary C
  317. initialization of successive elements.  Each initializer element that
  318. does not have a label applies to the next consecutive element of the
  319. array or structure.  For example,
  320.  
  321.      int a[6] = { [1] = v1, v2, [4] = v4 };
  322.  
  323. is equivalent to
  324.  
  325.      int a[6] = { 0, v1, v2, 0, v4, 0 };
  326.  
  327.    Labeling the elements of an array initializer is especially useful
  328. when the indices are characters or belong to an `enum' type.  For
  329. example:
  330.  
  331.      int whitespace[256]
  332.        = { [' '] = 1, ['\t'] = 1, ['\h'] = 1,
  333.            ['\f'] = 1, ['\n'] = 1, ['\r'] = 1 };
  334.  
  335. 
  336. File: gcc.info,  Node: Case Ranges,  Next: Function Attributes,  Prev: Cast to Union,  Up: C Extensions
  337.  
  338. Case Ranges
  339. ===========
  340.  
  341.    You can specify a range of consecutive values in a single `case'
  342. label, like this:
  343.  
  344.      case LOW ... HIGH:
  345.  
  346. This has the same effect as the proper number of individual `case'
  347. labels, one for each integer value from LOW to HIGH, inclusive.
  348.  
  349.    This feature is especially useful for ranges of ASCII character
  350. codes:
  351.  
  352.      case 'A' ... 'Z':
  353.  
  354.    *Be careful:* Write spaces around the `...', for otherwise it may be
  355. parsed wrong when you use it with integer values.  For example, write
  356. this:
  357.  
  358.      case 1 ... 5:
  359.  
  360. rather than this:
  361.  
  362.      case 1...5:
  363.  
  364. 
  365. File: gcc.info,  Node: Cast to Union,  Next: Case Ranges,  Prev: Labeled Elements,  Up: C Extensions
  366.  
  367. Cast to a Union Type
  368. ====================
  369.  
  370.    A cast to union type is similar to other casts, except that the type
  371. specified is a union type.  You can specify the type either with `union
  372. TAG' or with a typedef name.  A cast to union is actually a constructor
  373. though, not a cast, and hence does not yield an lvalue like normal
  374. casts.  (*Note Constructors::.)
  375.  
  376.    The types that may be cast to the union type are those of the members
  377. of the union.  Thus, given the following union and variables:
  378.  
  379.      union foo { int i; double d; };
  380.      int x;
  381.      double y;
  382.  
  383. both `x' and `y' can be cast to type `union' foo.
  384.  
  385.    Using the cast as the right-hand side of an assignment to a variable
  386. of union type is equivalent to storing in a member of the union:
  387.  
  388.      union foo u;
  389.      ...
  390.      u = (union foo) x  ==  u.i = x
  391.      u = (union foo) y  ==  u.d = y
  392.  
  393.    You can also use the union cast as a function argument:
  394.  
  395.      void hack (union foo);
  396.      ...
  397.      hack ((union foo) x);
  398.  
  399. 
  400. File: gcc.info,  Node: Function Attributes,  Next: Function Prototypes,  Prev: Case Ranges,  Up: C Extensions
  401.  
  402. Declaring Attributes of Functions
  403. =================================
  404.  
  405.    In GNU C, you declare certain things about functions called in your
  406. program which help the compiler optimize function calls and check your
  407. code more carefully.
  408.  
  409.    The keyword `__attribute__' allows you to specify special attributes
  410. when making a declaration.  This keyword is followed by an attribute
  411. specification inside double parentheses.  Nine attributes, `noreturn',
  412. `const', `format', `no_instrument_function', `section', `constructor',
  413. `destructor', `unused' and `weak' are currently defined for functions.
  414. Other attributes, including `section' are supported for variables
  415. declarations (*note Variable Attributes::.) and for types (*note Type
  416. Attributes::.).
  417.  
  418.    You may also specify attributes with `__' preceding and following
  419. each keyword.  This allows you to use them in header files without
  420. being concerned about a possible macro of the same name.  For example,
  421. you may use `__noreturn__' instead of `noreturn'.
  422.  
  423. `noreturn'
  424.      A few standard library functions, such as `abort' and `exit',
  425.      cannot return.  GNU CC knows this automatically.  Some programs
  426.      define their own functions that never return.  You can declare them
  427.      `noreturn' to tell the compiler this fact.  For example,
  428.  
  429.           void fatal () __attribute__ ((noreturn));
  430.           
  431.           void
  432.           fatal (...)
  433.           {
  434.             ... /* Print error message. */ ...
  435.             exit (1);
  436.           }
  437.  
  438.      The `noreturn' keyword tells the compiler to assume that `fatal'
  439.      cannot return.  It can then optimize without regard to what would
  440.      happen if `fatal' ever did return.  This makes slightly better
  441.      code.  More importantly, it helps avoid spurious warnings of
  442.      uninitialized variables.
  443.  
  444.      Do not assume that registers saved by the calling function are
  445.      restored before calling the `noreturn' function.
  446.  
  447.      It does not make sense for a `noreturn' function to have a return
  448.      type other than `void'.
  449.  
  450.      The attribute `noreturn' is not implemented in GNU C versions
  451.      earlier than 2.5.  An alternative way to declare that a function
  452.      does not return, which works in the current version and in some
  453.      older versions, is as follows:
  454.  
  455.           typedef void voidfn ();
  456.           
  457.           volatile voidfn fatal;
  458.  
  459. `const'
  460.      Many functions do not examine any values except their arguments,
  461.      and have no effects except the return value.  Such a function can
  462.      be subject to common subexpression elimination and loop
  463.      optimization just as an arithmetic operator would be.  These
  464.      functions should be declared with the attribute `const'.  For
  465.      example,
  466.  
  467.           int square (int) __attribute__ ((const));
  468.  
  469.      says that the hypothetical function `square' is safe to call fewer
  470.      times than the program says.
  471.  
  472.      The attribute `const' is not implemented in GNU C versions earlier
  473.      than 2.5.  An alternative way to declare that a function has no
  474.      side effects, which works in the current version and in some older
  475.      versions, is as follows:
  476.  
  477.           typedef int intfn ();
  478.           
  479.           extern const intfn square;
  480.  
  481.      This approach does not work in GNU C++ from 2.6.0 on, since the
  482.      language specifies that the `const' must be attached to the return
  483.      value.
  484.  
  485.      Note that a function that has pointer arguments and examines the
  486.      data pointed to must *not* be declared `const'.  Likewise, a
  487.      function that calls a non-`const' function usually must not be
  488.      `const'.  It does not make sense for a `const' function to return
  489.      `void'.
  490.  
  491. `format (ARCHETYPE, STRING-INDEX, FIRST-TO-CHECK)'
  492.      The `format' attribute specifies that a function takes `printf',
  493.      `scanf', or `strftime' style arguments which should be type-checked
  494.      against a format string.  For example, the declaration:
  495.  
  496.           extern int
  497.           my_printf (void *my_object, const char *my_format, ...)
  498.                 __attribute__ ((format (printf, 2, 3)));
  499.  
  500.      causes the compiler to check the arguments in calls to `my_printf'
  501.      for consistency with the `printf' style format string argument
  502.      `my_format'.
  503.  
  504.      The parameter ARCHETYPE determines how the format string is
  505.      interpreted, and should be either `printf', `scanf', or
  506.      `strftime'.  The parameter STRING-INDEX specifies which argument
  507.      is the format string argument (starting from 1), while
  508.      FIRST-TO-CHECK is the number of the first argument to check
  509.      against the format string.  For functions where the arguments are
  510.      not available to be checked (such as `vprintf'), specify the third
  511.      parameter as zero.  In this case the compiler only checks the
  512.      format string for consistency.
  513.  
  514.      In the example above, the format string (`my_format') is the second
  515.      argument of the function `my_print', and the arguments to check
  516.      start with the third argument, so the correct parameters for the
  517.      format attribute are 2 and 3.
  518.  
  519.      The `format' attribute allows you to identify your own functions
  520.      which take format strings as arguments, so that GNU CC can check
  521.      the calls to these functions for errors.  The compiler always
  522.      checks formats for the ANSI library functions `printf', `fprintf',
  523.      `sprintf', `scanf', `fscanf', `sscanf', `strftime', `vprintf',
  524.      `vfprintf' and `vsprintf' whenever such warnings are requested
  525.      (using `-Wformat'), so there is no need to modify the header file
  526.      `stdio.h'.
  527.  
  528. `format_arg (STRING-INDEX)'
  529.      The `format_arg' attribute specifies that a function takes
  530.      `printf' or `scanf' style arguments, modifies it (for example, to
  531.      translate it into another language), and passes it to a `printf'
  532.      or `scanf' style function.  For example, the declaration:
  533.  
  534.           extern char *
  535.           my_dgettext (char *my_domain, const char *my_format)
  536.                 __attribute__ ((format_arg (2)));
  537.  
  538.      causes the compiler to check the arguments in calls to
  539.      `my_dgettext' whose result is passed to a `printf', `scanf', or
  540.      `strftime' type function for consistency with the `printf' style
  541.      format string argument `my_format'.
  542.  
  543.      The parameter STRING-INDEX specifies which argument is the format
  544.      string argument (starting from 1).
  545.  
  546.      The `format-arg' attribute allows you to identify your own
  547.      functions which modify format strings, so that GNU CC can check the
  548.      calls to `printf', `scanf', or `strftime' function whose operands
  549.      are a call to one of your own function.  The compiler always
  550.      treats `gettext', `dgettext', and `dcgettext' in this manner.
  551.  
  552. `no_instrument_function'
  553.      If `-finstrument-functions' is given, profiling function calls will
  554.      be generated at entry and exit of most user-compiled functions.
  555.      Functions with this attribute will not be so instrumented.
  556.  
  557. `section ("section-name")'
  558.      Normally, the compiler places the code it generates in the `text'
  559.      section.  Sometimes, however, you need additional sections, or you
  560.      need certain particular functions to appear in special sections.
  561.      The `section' attribute specifies that a function lives in a
  562.      particular section.  For example, the declaration:
  563.  
  564.           extern void foobar (void) __attribute__ ((section ("bar")));
  565.  
  566.      puts the function `foobar' in the `bar' section.
  567.  
  568.      Some file formats do not support arbitrary sections so the
  569.      `section' attribute is not available on all platforms.  If you
  570.      need to map the entire contents of a module to a particular
  571.      section, consider using the facilities of the linker instead.
  572.  
  573. `constructor'
  574. `destructor'
  575.      The `constructor' attribute causes the function to be called
  576.      automatically before execution enters `main ()'.  Similarly, the
  577.      `destructor' attribute causes the function to be called
  578.      automatically after `main ()' has completed or `exit ()' has been
  579.      called.  Functions with these attributes are useful for
  580.      initializing data that will be used implicitly during the
  581.      execution of the program.
  582.  
  583.      These attributes are not currently implemented for Objective C.
  584.  
  585. `unused'
  586.      This attribute, attached to a function, means that the function is
  587.      meant to be possibly unused.  GNU CC will not produce a warning
  588.      for this function.  GNU C++ does not currently support this
  589.      attribute as definitions without parameters are valid in C++.
  590.  
  591. `weak'
  592.      The `weak' attribute causes the declaration to be emitted as a weak
  593.      symbol rather than a global.  This is primarily useful in defining
  594.      library functions which can be overridden in user code, though it
  595.      can also be used with non-function declarations.  Weak symbols are
  596.      supported for ELF targets, and also for a.out targets when using
  597.      the GNU assembler and linker.
  598.  
  599. `alias ("target")'
  600.      The `alias' attribute causes the declaration to be emitted as an
  601.      alias for another symbol, which must be specified.  For instance,
  602.  
  603.           void __f () { /* do something */; }
  604.           void f () __attribute__ ((weak, alias ("__f")));
  605.  
  606.      declares `f' to be a weak alias for `__f'.  In C++, the mangled
  607.      name for the target must be used.
  608.  
  609.      Not all target machines support this attribute.
  610.  
  611. `no_check_memory_usage'
  612.      If `-fcheck-memory-usage' is given, calls to support routines will
  613.      be generated before most memory accesses, to permit support code to
  614.      record usage and detect uses of uninitialized or unallocated
  615.      storage.  Since the compiler cannot handle them properly, `asm'
  616.      statements are not allowed.  Declaring a function with this
  617.      attribute disables the memory checking code for that function,
  618.      permitting the use of `asm' statements without requiring separate
  619.      compilation with different options, and allowing you to write
  620.      support routines of your own if you wish, without getting infinite
  621.      recursion if they get compiled with this option.
  622.  
  623. `regparm (NUMBER)'
  624.      On the Intel 386, the `regparm' attribute causes the compiler to
  625.      pass up to NUMBER integer arguments in registers EAX, EDX, and ECX
  626.      instead of on the stack.  Functions that take a variable number of
  627.      arguments will continue to be passed all of their arguments on the
  628.      stack.
  629.  
  630. `stdcall'
  631.      On the Intel 386, the `stdcall' attribute causes the compiler to
  632.      assume that the called function will pop off the stack space used
  633.      to pass arguments, unless it takes a variable number of arguments.
  634.  
  635.      The PowerPC compiler for Windows NT currently ignores the `stdcall'
  636.      attribute.
  637.  
  638. `cdecl'
  639.      On the Intel 386, the `cdecl' attribute causes the compiler to
  640.      assume that the calling function will pop off the stack space used
  641.      to pass arguments.  This is useful to override the effects of the
  642.      `-mrtd' switch.
  643.  
  644.      The PowerPC compiler for Windows NT currently ignores the `cdecl'
  645.      attribute.
  646.  
  647. `longcall'
  648.      On the RS/6000 and PowerPC, the `longcall' attribute causes the
  649.      compiler to always call the function via a pointer, so that
  650.      functions which reside further than 64 megabytes (67,108,864
  651.      bytes) from the current location can be called.
  652.  
  653. `dllimport'
  654.      On the PowerPC running Windows NT, the `dllimport' attribute causes
  655.      the compiler to call the function via a global pointer to the
  656.      function pointer that is set up by the Windows NT dll library.
  657.      The pointer name is formed by combining `__imp_' and the function
  658.      name.
  659.  
  660. `dllexport'
  661.      On the PowerPC running Windows NT, the `dllexport' attribute causes
  662.      the compiler to provide a global pointer to the function pointer,
  663.      so that it can be called with the `dllimport' attribute.  The
  664.      pointer name is formed by combining `__imp_' and the function name.
  665.  
  666. `exception (EXCEPT-FUNC [, EXCEPT-ARG])'
  667.      On the PowerPC running Windows NT, the `exception' attribute causes
  668.      the compiler to modify the structured exception table entry it
  669.      emits for the declared function.  The string or identifier
  670.      EXCEPT-FUNC is placed in the third entry of the structured
  671.      exception table.  It represents a function, which is called by the
  672.      exception handling mechanism if an exception occurs.  If it was
  673.      specified, the string or identifier EXCEPT-ARG is placed in the
  674.      fourth entry of the structured exception table.
  675.  
  676. `function_vector'
  677.      Use this option on the H8/300 and H8/300H to indicate that the
  678.      specified function should be called through the function vector.
  679.      Calling a function through the function vector will reduce code
  680.      size, however; the function vector has a limited size (maximum 128
  681.      entries on the H8/300 and 64 entries on the H8/300H) and shares
  682.      space with the interrupt vector.
  683.  
  684.      You must use GAS and GLD from GNU binutils version 2.7 or later for
  685.      this option to work correctly.
  686.  
  687. `interrupt_handler'
  688.      Use this option on the H8/300 and H8/300H to indicate that the
  689.      specified function is an interrupt handler.  The compiler will
  690.      generate function entry and exit sequences suitable for use in an
  691.      interrupt handler when this attribute is present.
  692.  
  693. `eightbit_data'
  694.      Use this option on the H8/300 and H8/300H to indicate that the
  695.      specified variable should be placed into the eight bit data
  696.      section.  The compiler will generate more efficient code for
  697.      certain operations on data in the eight bit data area.  Note the
  698.      eight bit data area is limited to 256 bytes of data.
  699.  
  700.      You must use GAS and GLD from GNU binutils version 2.7 or later for
  701.      this option to work correctly.
  702.  
  703. `tiny_data'
  704.      Use this option on the H8/300H to indicate that the specified
  705.      variable should be placed into the tiny data section.  The
  706.      compiler will generate more efficient code for loads and stores on
  707.      data in the tiny data section.  Note the tiny data area is limited
  708.      to slightly under 32kbytes of data.
  709.  
  710. `interrupt'
  711.      Use this option on the M32R/D to indicate that the specified
  712.      function is an interrupt handler.  The compiler will generate
  713.      function entry and exit sequences suitable for use in an interrupt
  714.      handler when this attribute is present.
  715.  
  716. `model (MODEL-NAME)'
  717.      Use this attribute on the M32R/D to set the addressability of an
  718.      object, and the code generated for a function.  The identifier
  719.      MODEL-NAME is one of `small', `medium', or `large', representing
  720.      each of the code models.
  721.  
  722.      Small model objects live in the lower 16MB of memory (so that their
  723.      addresses can be loaded with the `ld24' instruction), and are
  724.      callable with the `bl' instruction.
  725.  
  726.      Medium model objects may live anywhere in the 32 bit address space
  727.      (the compiler will generate `seth/add3' instructions to load their
  728.      addresses), and are callable with the `bl' instruction.
  729.  
  730.      Large model objects may live anywhere in the 32 bit address space
  731.      (the compiler will generate `seth/add3' instructions to load their
  732.      addresses), and may not be reachable with the `bl' instruction
  733.      (the compiler will generate the much slower `seth/add3/jl'
  734.      instruction sequence).
  735.  
  736.    You can specify multiple attributes in a declaration by separating
  737. them by commas within the double parentheses or by immediately
  738. following an attribute declaration with another attribute declaration.
  739.  
  740.    Some people object to the `__attribute__' feature, suggesting that
  741. ANSI C's `#pragma' should be used instead.  There are two reasons for
  742. not doing this.
  743.  
  744.   1. It is impossible to generate `#pragma' commands from a macro.
  745.  
  746.   2. There is no telling what the same `#pragma' might mean in another
  747.      compiler.
  748.  
  749.    These two reasons apply to almost any application that might be
  750. proposed for `#pragma'.  It is basically a mistake to use `#pragma' for
  751. *anything*.
  752.  
  753. 
  754. File: gcc.info,  Node: Function Prototypes,  Next: C++ Comments,  Prev: Function Attributes,  Up: C Extensions
  755.  
  756. Prototypes and Old-Style Function Definitions
  757. =============================================
  758.  
  759.    GNU C extends ANSI C to allow a function prototype to override a
  760. later old-style non-prototype definition.  Consider the following
  761. example:
  762.  
  763.      /* Use prototypes unless the compiler is old-fashioned.  */
  764.      #ifdef __STDC__
  765.      #define P(x) x
  766.      #else
  767.      #define P(x) ()
  768.      #endif
  769.      
  770.      /* Prototype function declaration.  */
  771.      int isroot P((uid_t));
  772.      
  773.      /* Old-style function definition.  */
  774.      int
  775.      isroot (x)   /* ??? lossage here ??? */
  776.           uid_t x;
  777.      {
  778.        return x == 0;
  779.      }
  780.  
  781.    Suppose the type `uid_t' happens to be `short'.  ANSI C does not
  782. allow this example, because subword arguments in old-style
  783. non-prototype definitions are promoted.  Therefore in this example the
  784. function definition's argument is really an `int', which does not match
  785. the prototype argument type of `short'.
  786.  
  787.    This restriction of ANSI C makes it hard to write code that is
  788. portable to traditional C compilers, because the programmer does not
  789. know whether the `uid_t' type is `short', `int', or `long'.  Therefore,
  790. in cases like these GNU C allows a prototype to override a later
  791. old-style definition.  More precisely, in GNU C, a function prototype
  792. argument type overrides the argument type specified by a later
  793. old-style definition if the former type is the same as the latter type
  794. before promotion.  Thus in GNU C the above example is equivalent to the
  795. following:
  796.  
  797.      int isroot (uid_t);
  798.      
  799.      int
  800.      isroot (uid_t x)
  801.      {
  802.        return x == 0;
  803.      }
  804.  
  805.    GNU C++ does not support old-style function definitions, so this
  806. extension is irrelevant.
  807.  
  808. 
  809. File: gcc.info,  Node: C++ Comments,  Next: Dollar Signs,  Prev: Function Prototypes,  Up: C Extensions
  810.  
  811. C++ Style Comments
  812. ==================
  813.  
  814.    In GNU C, you may use C++ style comments, which start with `//' and
  815. continue until the end of the line.  Many other C implementations allow
  816. such comments, and they are likely to be in a future C standard.
  817. However, C++ style comments are not recognized if you specify `-ansi'
  818. or `-traditional', since they are incompatible with traditional
  819. constructs like `dividend//*comment*/divisor'.
  820.  
  821. 
  822. File: gcc.info,  Node: Dollar Signs,  Next: Character Escapes,  Prev: C++ Comments,  Up: C Extensions
  823.  
  824. Dollar Signs in Identifier Names
  825. ================================
  826.  
  827.    In GNU C, you may normally use dollar signs in identifier names.
  828. This is because many traditional C implementations allow such
  829. identifiers.  However, dollar signs in identifiers are not supported on
  830. a few target machines, typically because the target assembler does not
  831. allow them.
  832.  
  833. 
  834. File: gcc.info,  Node: Character Escapes,  Next: Variable Attributes,  Prev: Dollar Signs,  Up: C Extensions
  835.  
  836. The Character <ESC> in Constants
  837. ================================
  838.  
  839.    You can use the sequence `\e' in a string or character constant to
  840. stand for the ASCII character <ESC>.
  841.  
  842. 
  843. File: gcc.info,  Node: Alignment,  Next: Inline,  Prev: Type Attributes,  Up: C Extensions
  844.  
  845. Inquiring on Alignment of Types or Variables
  846. ============================================
  847.  
  848.    The keyword `__alignof__' allows you to inquire about how an object
  849. is aligned, or the minimum alignment usually required by a type.  Its
  850. syntax is just like `sizeof'.
  851.  
  852.    For example, if the target machine requires a `double' value to be
  853. aligned on an 8-byte boundary, then `__alignof__ (double)' is 8.  This
  854. is true on many RISC machines.  On more traditional machine designs,
  855. `__alignof__ (double)' is 4 or even 2.
  856.  
  857.    Some machines never actually require alignment; they allow reference
  858. to any data type even at an odd addresses.  For these machines,
  859. `__alignof__' reports the *recommended* alignment of a type.
  860.  
  861.    When the operand of `__alignof__' is an lvalue rather than a type,
  862. the value is the largest alignment that the lvalue is known to have.
  863. It may have this alignment as a result of its data type, or because it
  864. is part of a structure and inherits alignment from that structure.  For
  865. example, after this declaration:
  866.  
  867.      struct foo { int x; char y; } foo1;
  868.  
  869. the value of `__alignof__ (foo1.y)' is probably 2 or 4, the same as
  870. `__alignof__ (int)', even though the data type of `foo1.y' does not
  871. itself demand any alignment.
  872.  
  873.    A related feature which lets you specify the alignment of an object
  874. is `__attribute__ ((aligned (ALIGNMENT)))'; see the following section.
  875.  
  876. 
  877. File: gcc.info,  Node: Variable Attributes,  Next: Type Attributes,  Prev: Character Escapes,  Up: C Extensions
  878.  
  879. Specifying Attributes of Variables
  880. ==================================
  881.  
  882.    The keyword `__attribute__' allows you to specify special attributes
  883. of variables or structure fields.  This keyword is followed by an
  884. attribute specification inside double parentheses.  Eight attributes
  885. are currently defined for variables: `aligned', `mode', `nocommon',
  886. `packed', `section', `transparent_union', `unused', and `weak'.  Other
  887. attributes are available for functions (*note Function Attributes::.)
  888. and for types (*note Type Attributes::.).
  889.  
  890.    You may also specify attributes with `__' preceding and following
  891. each keyword.  This allows you to use them in header files without
  892. being concerned about a possible macro of the same name.  For example,
  893. you may use `__aligned__' instead of `aligned'.
  894.  
  895. `aligned (ALIGNMENT)'
  896.      This attribute specifies a minimum alignment for the variable or
  897.      structure field, measured in bytes.  For example, the declaration:
  898.  
  899.           int x __attribute__ ((aligned (16))) = 0;
  900.  
  901.      causes the compiler to allocate the global variable `x' on a
  902.      16-byte boundary.  On a 68040, this could be used in conjunction
  903.      with an `asm' expression to access the `move16' instruction which
  904.      requires 16-byte aligned operands.
  905.  
  906.      You can also specify the alignment of structure fields.  For
  907.      example, to create a double-word aligned `int' pair, you could
  908.      write:
  909.  
  910.           struct foo { int x[2] __attribute__ ((aligned (8))); };
  911.  
  912.      This is an alternative to creating a union with a `double' member
  913.      that forces the union to be double-word aligned.
  914.  
  915.      It is not possible to specify the alignment of functions; the
  916.      alignment of functions is determined by the machine's requirements
  917.      and cannot be changed.  You cannot specify alignment for a typedef
  918.      name because such a name is just an alias, not a distinct type.
  919.  
  920.      As in the preceding examples, you can explicitly specify the
  921.      alignment (in bytes) that you wish the compiler to use for a given
  922.      variable or structure field.  Alternatively, you can leave out the
  923.      alignment factor and just ask the compiler to align a variable or
  924.      field to the maximum useful alignment for the target machine you
  925.      are compiling for.  For example, you could write:
  926.  
  927.           short array[3] __attribute__ ((aligned));
  928.  
  929.      Whenever you leave out the alignment factor in an `aligned'
  930.      attribute specification, the compiler automatically sets the
  931.      alignment for the declared variable or field to the largest
  932.      alignment which is ever used for any data type on the target
  933.      machine you are compiling for.  Doing this can often make copy
  934.      operations more efficient, because the compiler can use whatever
  935.      instructions copy the biggest chunks of memory when performing
  936.      copies to or from the variables or fields that you have aligned
  937.      this way.
  938.  
  939.      The `aligned' attribute can only increase the alignment; but you
  940.      can decrease it by specifying `packed' as well.  See below.
  941.  
  942.      Note that the effectiveness of `aligned' attributes may be limited
  943.      by inherent limitations in your linker.  On many systems, the
  944.      linker is only able to arrange for variables to be aligned up to a
  945.      certain maximum alignment.  (For some linkers, the maximum
  946.      supported alignment may be very very small.)  If your linker is
  947.      only able to align variables up to a maximum of 8 byte alignment,
  948.      then specifying `aligned(16)' in an `__attribute__' will still
  949.      only provide you with 8 byte alignment.  See your linker
  950.      documentation for further information.
  951.  
  952. `mode (MODE)'
  953.      This attribute specifies the data type for the
  954.      declaration--whichever type corresponds to the mode MODE.  This in
  955.      effect lets you request an integer or floating point type
  956.      according to its width.
  957.  
  958.      You may also specify a mode of `byte' or `__byte__' to indicate
  959.      the mode corresponding to a one-byte integer, `word' or `__word__'
  960.      for the mode of a one-word integer, and `pointer' or `__pointer__'
  961.      for the mode used to represent pointers.
  962.  
  963. `nocommon'
  964.      This attribute specifies requests GNU CC not to place a variable
  965.      "common" but instead to allocate space for it directly.  If you
  966.      specify the `-fno-common' flag, GNU CC will do this for all
  967.      variables.
  968.  
  969.      Specifying the `nocommon' attribute for a variable provides an
  970.      initialization of zeros.  A variable may only be initialized in one
  971.      source file.
  972.  
  973. `packed'
  974.      The `packed' attribute specifies that a variable or structure field
  975.      should have the smallest possible alignment--one byte for a
  976.      variable, and one bit for a field, unless you specify a larger
  977.      value with the `aligned' attribute.
  978.  
  979.      Here is a structure in which the field `x' is packed, so that it
  980.      immediately follows `a':
  981.  
  982.           struct foo
  983.           {
  984.             char a;
  985.             int x[2] __attribute__ ((packed));
  986.           };
  987.  
  988. `section ("section-name")'
  989.      Normally, the compiler places the objects it generates in sections
  990.      like `data' and `bss'.  Sometimes, however, you need additional
  991.      sections, or you need certain particular variables to appear in
  992.      special sections, for example to map to special hardware.  The
  993.      `section' attribute specifies that a variable (or function) lives
  994.      in a particular section.  For example, this small program uses
  995.      several specific section names:
  996.  
  997.           struct duart a __attribute__ ((section ("DUART_A"))) = { 0 };
  998.           struct duart b __attribute__ ((section ("DUART_B"))) = { 0 };
  999.           char stack[10000] __attribute__ ((section ("STACK"))) = { 0 };
  1000.           int init_data __attribute__ ((section ("INITDATA"))) = 0;
  1001.           
  1002.           main()
  1003.           {
  1004.             /* Initialize stack pointer */
  1005.             init_sp (stack + sizeof (stack));
  1006.           
  1007.             /* Initialize initialized data */
  1008.             memcpy (&init_data, &data, &edata - &data);
  1009.           
  1010.             /* Turn on the serial ports */
  1011.             init_duart (&a);
  1012.             init_duart (&b);
  1013.           }
  1014.  
  1015.      Use the `section' attribute with an *initialized* definition of a
  1016.      *global* variable, as shown in the example.  GNU CC issues a
  1017.      warning and otherwise ignores the `section' attribute in
  1018.      uninitialized variable declarations.
  1019.  
  1020.      You may only use the `section' attribute with a fully initialized
  1021.      global definition because of the way linkers work.  The linker
  1022.      requires each object be defined once, with the exception that
  1023.      uninitialized variables tentatively go in the `common' (or `bss')
  1024.      section and can be multiply "defined".  You can force a variable
  1025.      to be initialized with the `-fno-common' flag or the `nocommon'
  1026.      attribute.
  1027.  
  1028.      Some file formats do not support arbitrary sections so the
  1029.      `section' attribute is not available on all platforms.  If you
  1030.      need to map the entire contents of a module to a particular
  1031.      section, consider using the facilities of the linker instead.
  1032.  
  1033. `transparent_union'
  1034.      This attribute, attached to a function parameter which is a union,
  1035.      means that the corresponding argument may have the type of any
  1036.      union member, but the argument is passed as if its type were that
  1037.      of the first union member.  For more details see *Note Type
  1038.      Attributes::.  You can also use this attribute on a `typedef' for
  1039.      a union data type; then it applies to all function parameters with
  1040.      that type.
  1041.  
  1042. `unused'
  1043.      This attribute, attached to a variable, means that the variable is
  1044.      meant to be possibly unused.  GNU CC will not produce a warning
  1045.      for this variable.
  1046.  
  1047. `weak'
  1048.      The `weak' attribute is described in *Note Function Attributes::.
  1049.  
  1050. `model (MODEL-NAME)'
  1051.      Use this attribute on the M32R/D to set the addressability of an
  1052.      object.  The identifier MODEL-NAME is one of `small', `medium', or
  1053.      `large', representing each of the code models.
  1054.  
  1055.      Small model objects live in the lower 16MB of memory (so that their
  1056.      addresses can be loaded with the `ld24' instruction).
  1057.  
  1058.      Medium and large model objects may live anywhere in the 32 bit
  1059.      address space (the compiler will generate `seth/add3' instructions
  1060.      to load their addresses).
  1061.  
  1062.    To specify multiple attributes, separate them by commas within the
  1063. double parentheses: for example, `__attribute__ ((aligned (16),
  1064. packed))'.
  1065.  
  1066.